package edu.gatech.cc.hwa.server.security;

import java.nio.charset.Charset;

public class StringByteArrayConverter {

	private static final String APP_DEFAULT_ENCODING = "iso-8859-1";
	
	public static byte[] convertToSystemDefaultByteArray(String text) {
		return text.getBytes(getSystemDefaultCharset());
	}
	
	public static String convertToSystemDefaultString(byte[] array) {
		return new String(array, getSystemDefaultCharset());
	}
	
	public static byte[] convertToByteArray(String text) {
		return text.getBytes(getApplicationDefaultCharset());
	}
	
	public static String convertToString(byte[] array) {
		return new String(array, getApplicationDefaultCharset());
	}
	
	private static Charset getApplicationDefaultCharset() {
		return Charset.availableCharsets().get(APP_DEFAULT_ENCODING);
	}
	
	private static Charset getSystemDefaultCharset() {
		return Charset.defaultCharset();
	}
}
